package com.cslg.questionnaires.controller;

import com.cslg.questionnaires.entity.Teacher;
import com.cslg.questionnaires.service.CheckFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Controller
public class TeacherCheckFormController {
    @Autowired
    private CheckFormService checkFormService;

    @GetMapping("/TeacherCheckForm")
    public ModelAndView GetCheckPage(@RequestParam("page") int page, HttpSession session){
        String userType = (String)session.getAttribute("userType");
        Teacher teacher = (Teacher)session.getAttribute("user");
        int teacherId = teacher.getId();
        String username = teacher.getUsername();
        String account = teacher.getAccount();
        HashMap<String,Object> msg = checkFormService.getAllForm(teacherId,userType,page);
        msg.put("userType",userType);
        msg.put("username",username);
        msg.put("account",account);
        return new ModelAndView("CheckForm", msg);
    }

    @GetMapping("/TeacherCheckForm/{questionId}")
    public ModelAndView GetCheckPageByQuestionId(@PathVariable int questionId,@RequestParam("page") int page,HttpSession session){
        String userType = (String)session.getAttribute("userType");
        Teacher teacher = (Teacher)session.getAttribute("user");
        int teacherId = teacher.getId();
        String username = teacher.getUsername();
        String account = teacher.getAccount();
        HashMap<String,Object> msg = checkFormService.getFormByQuestionId(questionId,teacherId,userType,page);
        msg.put("userType",userType);
        msg.put("username",username);
        msg.put("account",account);
        return new ModelAndView("CheckForm", msg);
    }
}
